﻿/*
	Copyright © Bogdan Kobets 2011
	http://ElasticLogic.com
*/

using System.Collections.Generic;

namespace ElasticLogic.TagsMarker.Concepts
{

	public class Category<E> : Label
		where E : class
	{

		private Category()
			: base(true)
		{
		}

		public static Category<E> Create(string caption)
		{
			Category<E> category = new Category<E>();

			if (category.SetCaption(caption))
				return category;
			else
				return null;
		}

		public bool IsContainsTags
		{
			get { return Marker<E>.IsCategoryContainsTags(this); }
		}

		public List<Tag<E>> Tags
		{
			get { return Marker<E>.GetCategoryTags(this); }
		}

		public List<E> Entities
		{
			get { return Marker<E>.GetCategoryEntities(this); }
		}

		public bool ContainsTag(Tag<E> tag)
		{
			return Marker<E>.IsTagIncludedInCategory(tag, this);
		}

		public bool IncludeTag(Tag<E> tag)
		{
			return Marker<E>.IncludeTagInCategory(tag, this);
		}

		public bool ExcludeTag(Tag<E> tag)
		{
			return Marker<E>.ExcludeTagFromCategory(tag);
		}

		public void ClearTags()
		{
			Marker<E>.ClearCategoryTags(this);
		}

		/// <summary>
		/// Assign all tags from current category to entity
		/// </summary>
		public void IncludeTagsInEntity(E entity)
		{
			foreach (Tag<E> tag in this.Tags)
			{
				Marker<E>.IncludeTagInEntity(tag, entity);
			}
		}

		public void Remove()
		{
			Marker<E>.Categories.Remove(this);
		}

	}

}
